package com.ds.did.didrequest;

import java.net.DatagramSocket;
import java.net.InetAddress;

public class DIDRequest implements Runnable {
	 //This service will run on Port 4201...
	final private String localIp= "127.0.0.1";
	final private   int runnningPort=4201;
   DatagramSocket Socket=null;
   
   final private String pollKeyword = "HMSZ";
   final private String vmmServerIP = "74.63.233.38";
   
   String accountRecived [];

   InetAddress intAddress;

   //Ref. of Helper class
   DIDRequestHelper vssh=null;

   public DIDRequest() {
	   vssh = new DIDRequestHelper(vmmServerIP);
}
   
public static void main(String[] args) {

	try{
		while(true)
		{
			Thread.sleep(1000);
			Thread uclient=new Thread(new DIDRequest());
			uclient.start();
			uclient.join();
		}
	}
	catch(Exception E)
	{
		E.printStackTrace();

	}


}

@Override
public void run() {

	   try
	   {
		   //Connecting Localport...
		   intAddress = InetAddress.getByName(localIp);
		   Socket = new DatagramSocket(runnningPort, intAddress);
		   
		   while (true)
		   {
			   try
			   {                                
                  
				   Thread.sleep(5000);
				   //Getting Data From DS Virtual Server...
				   accountRecived = vssh.getClientAccountData(pollKeyword);
				  
				   if(accountRecived != null)
				   {
					  String mobileno = accountRecived[0];
					  String  msg =  accountRecived[1];
			          String msgDate = accountRecived[2];
			           
			           /** Method insert into Virtual table... */
					  vssh.getKeywordDetail(mobileno, msg, msgDate);
					   
					}
				   
		   }
	    catch(Exception E)
			{
				E.printStackTrace();
			}
			
		}
	}catch(Exception E){
	  
		Socket.close();
		Socket = null;
	   E.printStackTrace();
   }

	
}

}
